package cn.demoncat.util.lang.constant;

import cn.demoncat.util.lang.entity.ListStr;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * JDBC常量
 * 
 * @author 延晓磊
 *
 * @since 2020-9-7
 */
public class JDBCConstant {

	/**
	 * Mysql连接驱动
	 * 
	 * mysql-connector-java 5：驱动为com.mysql.jdbc.Driver
	 * mysql-connector-java 8：驱动为com.mysql.cj.jdbc.Driver，支持JDK8+
	 */
	public static final String MYSQL_DRIVER = "com.mysql.cj.jdbc.Driver";
	
	/**
	 * Mysql连接参数
	 */
	public static final String MYSQL_PARAM = "serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&rewriteBatchedStatements=true";

	/**
	 * MariaDB连接驱动
	 */
	public static final String MARIADB_DRIVER = "org.mariadb.jdbc.Driver";
	/**
	 * Oracle连接驱动
	 */
	public static final String ORACLE_DRIVER = "oracle.jdbc.OracleDriver";

	/**
	 * Mysql内置数据库
	 *
	 * @author 延晓磊
	 * @since 2020年10月09日
	 */
	public interface MysqlSysDb{
		/**
		 * 信息表
		 */
		String information_schema = "information_schema";
		/**
		 * 性能表
		 */
		String performance_schema = "performance_schema";

		/**
		 * 列表
		 */
		List<String> LIST = ListStr.getInstance(information_schema,performance_schema,"sys","mysql");
	}

	/**
	 * Mysql类型映射：sqlType==>javaType
	 */
	public static final Map<String, String> MYSQL_JAVA_TYPE = new HashMap<String, String>() {
		private static final long serialVersionUID = 1L;
		{
			put("bit", StringConstant.JAVA_INTEGER);
			put("tinyint", StringConstant.JAVA_INTEGER);
			put("smallint", StringConstant.JAVA_INTEGER);
			put("int", StringConstant.JAVA_INTEGER);
			put("integer", StringConstant.JAVA_INTEGER);
			put("bigint", "Long");
			put("double", "Double");
			put("float", "Float");
			put("decimal", "java.math.BigDecimal");
			put("char", StringConstant.JAVA_STRING);
			put("varchar", StringConstant.JAVA_STRING);
			put("text", StringConstant.JAVA_STRING);
			put("longtext", StringConstant.JAVA_STRING);
			put("date", "java.time.LocalDate");
			put("time", "java.time.LocalTime");
			put("datetime", "java.time.LocalDateTime");
		}
	};

	/**
	 * Mysql类型映射：sqlType==>jdbcType
	 */
	public static final Map<String, String> MYSQL_JDBC_TYPE = new HashMap<String, String>() {
		private static final long serialVersionUID = 1L;
		{
			put("bit", StringConstant.JDBC_NUMERIC);
			put("tinyint", StringConstant.JDBC_NUMERIC);
			put("smallint", StringConstant.JDBC_NUMERIC);
			put("int", StringConstant.JDBC_NUMERIC);
			put("integer", StringConstant.JDBC_NUMERIC);
			put("bigint", StringConstant.JDBC_NUMERIC);
			put("double", StringConstant.JDBC_NUMERIC);
			put("float", StringConstant.JDBC_NUMERIC);
			put("decimal", StringConstant.JDBC_NUMERIC);
			put("char", StringConstant.JDBC_VARCHAR);
			put("varchar", StringConstant.JDBC_VARCHAR);
			put("text", StringConstant.JDBC_LONGVARCHAR);
			put("longtext", StringConstant.JDBC_LONGVARCHAR);
			put("date", "DATE");
			put("time", "TIME");
			put("datetime", "TIMESTAMP");
		}
	};
}
